# Path and name of the build file
OUTPUT_PATH=output
BINARY_PATH=$(OUTPUT_PATH)/bin
APP=leeframe

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean

# cmd

## all: help
all: help

## deploy: clean and pull and build
deploy: clean pull build

## pull: pull the latest code
pull:
	@git pull

.PHONY: build
## build: build the binary
build: clean
	@echo "Building..."
	@$(GOBUILD) -o $(BINARY_PATH)/$(APP) main.go
	@mv $(BINARY_PATH)/$(APP) .

## run: run the binary
run: build
	@./$(APP) -env dev

## compile: compile the binary
compile:
    # 64bit
    # Linux
	@GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_PATH)/$(APP)-linux-amd64 main.go
    # Windows
	@GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_PATH)/$(APP)-windows-amd64.exe main.go
    # MacOS
	@GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_PATH)/$(APP)-darwin-amd64 main.go

## clean: clean the binary
clean:
	@echo "Cleaning..."
	@$(GOCLEAN)
	@rm -f ./$(APP)

# docker
.PHONY: docker-build
## docker-build: build the docker image
docker-build:
	@docker build -t $(APP):v1.0 .

## dock-compose-up: run the docker image
docker-compose-up: docker-build
	@docker-compose up -d

# golangci-lint
## install-lint: install golangci-lint
install-lint:
	@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.43.0)

## lint: run the golangci-lint
lint:
	@echo "Running $@ check"
	@$(go env GOPATH)/bin/golangci-lint run --timeout=5m --config .golangci.yml

## verifiers: run the verifiers
verifiers: install-lint lint

## init-git-hook: initialize the project
init-git-hook:
	@git config core.hooksPath .githooks
	@chmod +x .githooks/*

## help: print the help
help:
	@echo "Usage: \n"
	@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' |  sed -e 's/^/ /'
